home *** CD-ROM | disk | FTP | other *** search
- //========================================================================================
- //
- // File: ContainerView.cpp
- // Release Version: $ 1.0d11 $
- //
- // Author: Laurent Delamare
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Container.hpp"
-
- #ifndef CONTAINERVIEW_H
- #include "ContainerView.h"
- #endif
-
- #ifndef CONTAINERDEF_H
- #include "ContainerDef.h"
- #endif
-
- #ifndef CONTAINERPART_H
- #include "ContainerPart.h"
- #endif
-
- #ifndef CONTAINERFRM_H
- #include "ContainerFrm.h"
- #endif
-
- #ifndef EDITCMDS_H
- #include "EditCmds.h"
- #endif
-
- #ifndef CONTAINERSEL_H
- #include "ContainerSel.h"
- #endif
-
- #ifndef BASESHP_H
- #include "BaseShp.h"
- #endif
-
- #ifndef BOUNDSHP_H
- #include "BoundShp.h"
- #endif
-
- #ifndef LINESHP_H
- #include "LineShp.h"
- #endif
-
- #ifndef OVALSHP_H
- #include "OvalShp.h"
- #endif
-
- #ifndef RECTSHP_H
- #include "RectShp.h"
- #endif
-
- #ifndef RRECTSHP_H
- #include "RRectShp.h"
- #endif
-
- #ifndef TEXTSHP_H
- #include "TextShp.h"
- #endif
-
- #ifndef CONTAINERPRXY_H
- #include "ContainerPrxy.h"
- #endif
-
- #ifndef SHPTRAKR_H
- #include "ShpTrakr.h"
- #endif
-
- #ifndef CONTAINERCMDS_H
- #include "ContainerCmds.h"
- #endif
-
- #ifndef CONTAINERCLIP_H
- #include "ContainerClip.h"
- #endif
-
- #ifndef UTILS_H
- #include "Utils.h"
- #endif
-
- #ifndef CONTAINERDDCMD_H
- #include "ContainerDDCmd.h"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWSCROLR_H
- #include "FWScrolr.h"
- #endif
-
- #ifndef FWSCLBAR_H
- #include "FWSclBar.h"
- #endif
-
- #ifndef FWGROWBX_H
- #include "FWGrowBx.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- #ifndef FWCURSOR_H
- #include "FWCursor.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWLINSHP_H
- #include "FWLinShp.h"
- #endif
-
- #ifndef FWBMPSHP_H
- #include "FWBmpShp.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment containerframes
- #endif
-
- FW_DEFINE_CLASS_M1(CContainerView, FW_CView);
-
- //========================================================================================
- // CContainerView
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CContainerView::CContainerView
- //----------------------------------------------------------------------------------------
-
- CContainerView::CContainerView(Environment* ev, CContainerFrame* frame, FW_CRect& bounds, CContainerPart* containerPart) :
- FW_CView(ev, (FW_CView*)frame, bounds),
- fContainerPart(containerPart),
- fContainerFrame(frame)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerView::~CContainerView
- //----------------------------------------------------------------------------------------
-
- CContainerView::~CContainerView()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerView::Draw
- //----------------------------------------------------------------------------------------
-
- void CContainerView::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
- {
- // Render inside the content view
- FW_CViewContext vc(ev, this, odFacet, invalidShape);
- FW_CRect invalidRect;
- vc.GetClipRect(invalidRect);
-
- FW_CRectShape::RenderRect(vc, invalidRect, FW_kFill, FW_kWhiteEraseInk);
-
- // ----- Determine what to Render -----
- ODCanvas* canvas = odFacet->GetCanvas(ev);
- FW_Boolean dynamicCanvas = canvas->IsDynamic(ev);
-
- // ----- Render the grid -----
- if (dynamicCanvas)
- DrawGrid(ev, vc, invalidRect);
-
- // ----- Render every shape -----
- FW_CRect updateBox;
- FW_COrderedCollectionIterator ite(fContainerPart->GetShapeList());
- for (CBaseShape* theShape = (CBaseShape*)ite.First(); ite.IsNotComplete(); theShape = (CBaseShape*)ite.Next())
- {
- theShape->GetUpdateBox(updateBox);
- if (invalidRect.IsIntersecting(updateBox))
- theShape->RenderShape(ev, odFacet, vc);
- }
-
- // ----- Render selections Handles -----
- if (IsActive(ev) && dynamicCanvas) { // Do not render handles for print / print preview
- fContainerFrame->GetSelection(ev)->RenderSelectionHandles(ev, vc);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerView::AdjustCursor
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CContainerView::AdjustCursor(Environment *ev, ODFacet* facet, const FW_CPoint& where)
- {
- FW_Boolean cursorAdjusted = FW_CView::AdjustCursor(ev, facet, where);
-
- if (!cursorAdjusted &&
- fContainerPart->GetActiveFrame(ev) == (FW_CFrame*)fContainerFrame &&
- fContainerPart->GetTool() != kSelectTool)
- {
- FW_gCrossHairCursor.Select();
- cursorAdjusted = TRUE;
- }
-
- return cursorAdjusted;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerView::DoMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CContainerView::DoMouseDown(Environment *ev, const FW_CMouseEvent& theMouseEvent)
- {
- ODFacet* theFacet = theMouseEvent.GetFacet(ev);
- CContainerSelection* selection = fContainerFrame->GetSelection(ev);
-
- if (fContainerPart->GetTool() == kSelectTool)
- {
- if (selection->IsMouseInDraggableItem(ev, fContainerFrame, theMouseEvent, FALSE))
- {
- fContainerFrame->Drag(ev, theMouseEvent);
- }
- else if (!selection->Resize(ev, theMouseEvent))
- {
- selection->SelectWithRectangle(ev, theMouseEvent);
- }
-
- return TRUE;
- }
-
- // ----- If read only don't want to create a new shape -----
- if (fContainerPart->IsReadOnly(ev))
- {
- FW_Beep();
- return TRUE;
- }
-
- // ----- Create a new shape -----
- CBaseShape *theShape = fContainerPart->NewShape(ev, fContainerPart->GetTool() - kLine + kLineShape);
-
- FW_TRY
- {
- FW_PStyle trackStyle(fContainerPart->GetRenderVerb() == kFillOnly ? FW_kFixedPos1 : fContainerPart->GetPenSize(), FW_kGrayPat);
- FW_PInk trackInk(FW_kRGBBlack, FW_kRGBWhite, FW_kXOr);
- theShape->ChangeRenderVerb(ev, fContainerPart, kFrameOnly);
- theShape->SetFrameInk(trackInk);
- theShape->SetFrameStyle(trackStyle);
-
- CShapeTracker tracker(ev, this, theFacet, theShape, fContainerPart->IsAutoGridOn());
- if (tracker.Track(ev, theMouseEvent))
- {
- theShape->SetFrameInk(FW_kNormalInk);
- theShape->SetFrameStyle(FW_kNormalStyle);
-
- FW_CColor color;
-
- theShape->ChangeRenderVerb(ev, fContainerPart, fContainerPart->GetRenderVerb());
- theShape->ChangePenSize(ev, fContainerPart, fContainerPart->GetPenSize());
-
- fContainerPart->GetFrameColor(color);
- theShape->ChangeFrameColor(ev, fContainerPart, color);
-
- fContainerPart->GetFillColor(color);
- theShape->ChangeFillColor(ev, fContainerPart, color);
-
- theShape->ChangeFramePattern(ev, fContainerPart, fContainerPart->GetFramePattern());
- theShape->ChangeFillPattern(ev, fContainerPart, fContainerPart->GetFillPattern());
-
- CContainerShapeCommand* cmd = FW_NEW(CContainerShapeCommand,
- (ev, fContainerPart, fContainerFrame, selection, theShape));
- fContainerPart->ExecuteCommand(ev, cmd);
-
- FW_CRect dragRect;
- theShape->GetDragRect(dragRect);
-
- FW_CAcquiredODShape aqShape = ::FW_NewODShape(ev, dragRect);
-
- CContainerFacetClipper facetClipper(ev, fContainerPart);
- facetClipper.Clip(ev, fContainerFrame->GetPresentation(ev), aqShape);
-
- FW_CViewContext vc(ev, this, theMouseEvent.GetFacet(ev));
- theShape->RenderShape(ev, theFacet, vc);
-
- theShape->GetUpdateBox(ev, aqShape);
- fContainerFrame->GetPresentation(ev)->Invalidate(ev, aqShape, theFacet); // will not invalide theFacet
- }
- else
- {
- delete theShape;
- }
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- delete theShape;
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerView::DoMouseDownInEmbeddedFrameBorder
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CContainerView::DoMouseDownInEmbeddedFrameBorder(Environment *ev, const FW_CBorderMouseEvent& theBorderMouseEvent)
- {
- fContainerPart->SetTool(ev, kSelectTool);
-
- GetFrame(ev)->Drag(ev, theBorderMouseEvent);
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerView::DoMouseDownInEmbeddedFrame
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CContainerView::DoMouseDownInEmbeddedFrame(Environment* ev,
- const FW_CEmbeddedMouseEvent& theEmbeddedMouseEvent)
- {
- FW_Boolean handled = TRUE;
-
- if (theEmbeddedMouseEvent.GetNumberOfClicks(ev) > 1)
- GetFrame(ev)->OpenSelection(ev);
- else
- handled = DoMouseDown(ev, theEmbeddedMouseEvent);
-
- return handled;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerView::DrawGrid
- //----------------------------------------------------------------------------------------
-
- void CContainerView::DrawGrid(Environment *ev, FW_CGraphicContext& gc, const FW_CRect& invalidRect)
- {
- if (fContainerFrame->IsGraphicsGridOn())
- {
- FW_BitPattern vertical = {0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- FW_BitPattern horizontal = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80};
-
- FW_PPattern verticalPat(vertical);
- FW_PPattern horizontalPat(horizontal);
-
- FW_CFixed minY = FW_IntToFixed(72 * (invalidRect.top.AsInt() / 72));
- FW_CFixed maxY = FW_IntToFixed(72 * ((invalidRect.bottom + FW_kFixed72).AsInt() / 72));
- FW_CFixed minX = FW_IntToFixed(72 * (invalidRect.left.AsInt() / 72));
- FW_CFixed maxX = FW_IntToFixed(72 * ((invalidRect.right + FW_kFixed72).AsInt() / 72));
-
- // skip top-most and left-most lines
- FW_CFixed startX = (minX == FW_kFixed0) ? FW_kFixed72 : minX;
- FW_CFixed startY = (minY == FW_kFixed0) ? FW_kFixed72 : minY;
-
- FW_PStyle lineStyle(FW_IntToFixed(0), verticalPat);
- FW_CLineShape line(startX, minY, startX, maxY, FW_kNormalInk, lineStyle);
-
- for (FW_CFixed x = startX; x <= maxX; x += FW_kFixed72)
- {
- line.Render(gc);
- line.MoveShape(FW_kFixed72, FW_IntToFixed(0));
- }
-
- line.GetStyle()->SetPattern(horizontalPat);
- line.SetLineStart(minX, startY);
- line.SetLineEnd(maxX, startY);
-
- for (FW_CFixed y = startY; y <= maxY; y += FW_kFixed72)
- {
- line.Render(gc);
- line.MoveShape(FW_IntToFixed(0), FW_kFixed72);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerView::Activate
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CContainerView::Activate(Environment* ev)
- {
- FW_Boolean newState = FW_CView::Activate(ev);
-
- if (newState) {
- fContainerFrame->GetSelection(ev)->RenderAllHandles(ev, fContainerFrame);
- }
-
- return newState;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerView::Deactivate
- //----------------------------------------------------------------------------------------
-
- void CContainerView::Deactivate(Environment* ev)
- {
- FW_CView::Deactivate(ev);
- fContainerFrame->GetSelection(ev)->RenderAllHandles(ev, fContainerFrame);
- }
-